<template>
  <page-layout>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div>
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
            <a-col :md="6" :sm="12">
            <a-form-item label="合同名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input style="width:100%;" placeholder="请输入合同名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          </template>
          <a-col :md="6" :sm="8">
            <a-form-item>
              <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <vxe-grid
        id="uncheckContract"
        keep-source
        ref="vxeTable"
        :height="null"
        v-bind="options"
        @checkbox-change="onSelectChange"
        @checkbox-all="onSelectChange"
        @page-change="handlePageChange"
      >
      <template #dictText={row,column}>
        <span>{{getDictText(row,column)}}</span>
      </template>
      <template #action="{ row }">
        <template>
          <a @click="checkContract(row)" >审批</a>
        </template>
      </template>
    </vxe-grid>
    </div>
    <!-- table区域-end -->
    <CheckContractModal ref="modalForm" @check="modalFormOk"></CheckContractModal>  
  </a-card>
  </page-layout>
</template>

<script>
import PageLayout from '@/layouts/PageLayout'
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import { deleteAction } from '@/services/manage'
import CheckContractModal from './modules/CheckContractModal.vue'

export default {
  name: "uncheckContract",
  components: {
    PageLayout,
    CheckContractModal
  },
  mixins: [VxeTableMixin],
  data() {
    return {
      columns: [
        {
          type: 'seq',
          width: 60,
          field: 'seq'
        },
        {
          title: '合同名称',
          field: 'name',
          width: 200
        },
        {
          title: '合同编号',
          field: 'num',
          width: 200
        },
        {
          title: '客户名称',
          field: 'customerName',
          width: 200
        },
        {
          title: '销售机会',
          field: 'saleChance',
          width: 150
        },
        {
          title: '业务类型',
          field: 'businessType',
          formatter: 'dictText',
          width: 150
        },
        {
          title: '合同总价',
          field: 'money',
          width: 150
        },
        // {
        //   title: '整单折扣',
        //   field: 'discountRate'
        // },
        {
          title: '签订日期',
          field: 'orderDate',
          width: 150
        },
        {
          title:'是否开票',
          align:"center",
          field: 'billed',
          formatter: 'dictText',
          width: 150
        },
        {
          title: '合同负责人',
          field: 'ownerUserId',
          formatter: 'dictText',
          width: 150
        },
        {
          title: '状态',
          field: 'checkStatus',
          formatter: 'dictText',
          width: 150
        },
        {
          title: '备注',
          field: 'remark',
          width: 150
        },
        {
          title:'所属公司',
          align:"center",
          field: 'company',
          width: 200
        },
        {
          title:'所属部门',
          align:"center",
          field: 'createDept',
          formatter: 'dictText',
          width: 150
        },
        {
          title: '创建人',
          field: 'createBy',
          formatter: 'dictText',
          width: 150
        },
        {
          title: '创建时间',
          field: 'createTime',
          width: 150
        },
        {
          title: '更新时间',
          field: 'updateTime',
          width: 150
        },
        {
          title: '操作',
          field: 'action',
          align: "center",
          fixed: "right",
          slots: { default: 'action' },
          width: 120
        }
      ],
      url: {
        list: '/contract/listUnCheck',
        exportXlsUrl: '/contract/exportXls',
        importExcelUrl: '/contract/importExcel'
      },
      // 查询参数
      queryParam: {},
      selectedRowKeys: [],
      selectedRows: [],
      toggleSearchStatus: false,
      customTableToolbar: {
        buttons: [],
      },
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  created() {
  },
  methods: {
    getDictText(row, column) {
      return row[column.property] === true ? '是' : '否'
    },
    handleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { "id": id }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    checkContract(row){
      this.$refs.modalForm.showModal(row);
	  this.$refs.modalForm.disableSubmit = true
	  that.$refs.modalForm.title = '审批'
    },
    checkAfter(){
      console.log('checkAfter')
      this.loadData()
    }
  }
}
</script>
